﻿using System;
using System.Collections.Generic;
using System.Text;

namespace FDStudio.Core.Entities
{
    /*
     CreatedOn: 2018-01-27
     CreatedBy: Jackie Lee(天宇遊龍)
     */
    /// <summary>
    /// 分页列表
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class PagedList<T> : List<T>, IPagedList
    {
        /// <summary>
        /// 当前页面索引
        /// </summary>
        public long PageIndex { get; private set; }

        /// <summary>
        /// 每页面记录数
        /// </summary>
        public long PageSize { get; private set; }

        /// <summary>
        /// 总页数
        /// </summary>
        public long PageCount
        {
            get
            {
                if (PageSize == 0)
                    return 0;
                return RecordCount % PageSize == 0 ? RecordCount / PageSize : RecordCount / PageSize + 1;
            }
        }

        /// <summary>
        /// 总记录数
        /// </summary>
        public long RecordCount { get; private set; }

        public static PagedList<T> Create(IEnumerable<T> source, long recordCount, long pageSize, long pageIndex)
        {
            return new PagedList<T>(source)
            {
                RecordCount = recordCount,
                PageSize = pageSize,
                PageIndex = pageIndex
            };
        }

        public PagedList()
        {
        }

        private PagedList(IEnumerable<T> source) : base(source)
        {
        }
    }
}
